package pannelli.sub;
import com.cloudgarden.layout.AnchorConstraint;
import com.cloudgarden.layout.AnchorLayout;
import database.DB;

import java.awt.Dimension;
import javax.swing.*;

import oggetti.Cliente;
import oggetti.Magazzino;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class SubPannelloDatiAccessorio extends javax.swing.JPanel {
	private JTextField Marca;
	private JTextField Seriale;
	private JTextField IMEI;
	private JTextField Modello;
        private JTextField PrezzoAcquisto;
        private JTextField PrezzoRivendita;
        private JComboBox Condizione;
	
	public SubPannelloDatiAccessorio() {
		super();
		initGUI();
	}
	
	public Magazzino getAccessorioFromFields(){
		String marca_,modello_,imei_,seriale_,prezzoAcq,prezzoRiv,condizione_;
		marca_ = Marca.getText().length()>=0?Marca.getText():" ";
		modello_ = Modello.getText().length()>=0?Modello.getText():" ";
		imei_ = IMEI.getText().length()>=0?IMEI.getText():" ";
		seriale_ = Seriale.getText().length()>=0?Seriale.getText():" ";
                prezzoAcq = PrezzoAcquisto.getText().length()>0?PrezzoAcquisto.getText():"";
                prezzoRiv = PrezzoRivendita.getText().length()>0?PrezzoRivendita.getText():"";
                condizione_ = Condizione.getSelectedItem().toString();
                if(seriale_.length()>0 || imei_.length()>0){
                    int id = new DB().getFreeIdAccessorio();
                    Magazzino tmp = new Magazzino(id,marca_, modello_, imei_, seriale_,prezzoAcq,prezzoRiv,condizione_);
                    return tmp;
                }else return null;
	}
	
	private void initGUI() {
		try {
			AnchorLayout thisLayout = new AnchorLayout();
			this.setLayout(thisLayout);
			this.setPreferredSize(new java.awt.Dimension(530, 335));
			{
				Seriale = new JTextField();
				this.add(Seriale, new AnchorConstraint(117, 906, 288, 670, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				Seriale.setPreferredSize(new java.awt.Dimension(125, 57));
				Seriale.setBorder(BorderFactory.createTitledBorder("Seriale"));
			}
			{
				IMEI = new JTextField();
				this.add(IMEI, new AnchorConstraint(120, 648, 288, 419, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				IMEI.setPreferredSize(new java.awt.Dimension(121, 56));
				IMEI.setBorder(BorderFactory.createTitledBorder("Imei"));
			}
			{
				Modello = new JTextField();
				this.add(Modello, new AnchorConstraint(120, 397, 288, 244, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				Modello.setPreferredSize(new java.awt.Dimension(81, 56));
				Modello.setBorder(BorderFactory.createTitledBorder("Modello"));
			}
			{
				Marca = new JTextField();
				this.add(Marca, new AnchorConstraint(120, 221, 288, 23, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				Marca.setPreferredSize(new java.awt.Dimension(105, 56));
				Marca.setBorder(BorderFactory.createTitledBorder("Marca"));
			}
                        {
				PrezzoAcquisto = new JTextField();
				this.add(PrezzoAcquisto, new AnchorConstraint(305, 508, 446, 276, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				PrezzoAcquisto.setPreferredSize(new java.awt.Dimension(128, 56));
				PrezzoAcquisto.setBorder(BorderFactory.createTitledBorder("Prezzo Acquisto"));
			}
                        {
				PrezzoRivendita = new JTextField();
				this.add(PrezzoRivendita, new AnchorConstraint(300, 265, 446, 23, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				PrezzoRivendita.setPreferredSize(new java.awt.Dimension(128, 56));
				PrezzoRivendita.setBorder(BorderFactory.createTitledBorder("Prezzo Rivendita"));
			}
                        {
                                String[] def = {"Nuovo","Usato"};
                                DefaultComboBoxModel combo = new DefaultComboBoxModel(def);
                                Condizione = new JComboBox(combo);
                                this.add(Condizione, new AnchorConstraint(300, 900, 446, 519, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				Condizione.setPreferredSize(new java.awt.Dimension(202, 49));
				Condizione.setBorder(BorderFactory.createTitledBorder("Condizione"));
                        }
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
